#/usr/bin/python3
#coding=utf8

import base64,requests,time,hashlib,json




def create_safe(time):
	base64_before = base64.b64encode(('9622'+time).encode());
	return hashlib.md5(base64_before).hexdigest()


# def spider_python_spider(url,headers):
# 	return requests.request('GET',url,headers)




if __name__ == '__main__':
	url = 'https://www.python-spider.com/challenge/api/json'
	
	
	try:
		total_title_number = 0
		exist_zhaobiao = int(0)
		# txt_path = r'D:\TestCode\self_spider\1.txt'
		# f = open(txt_path,mode='a',encoding='utf-8')
		for j in range(1,86):
			param = {
				'page':j,
				'count':14,
			}
			timestamp = str(int(time.time()))
			headers = {
				'timestamp':timestamp,
				'safe':create_safe(timestamp)
			}
			res =  requests.request('GET',url,headers=headers,params=param,timeout=20)
			# print(res)
			jsonstrdata = json.loads(res.content)
			# print(type(jsonstrdata))
			if 'infos' in jsonstrdata:
				infos = jsonstrdata['infos']
				
				for i in infos:
					# total_title_number=total_title_number+1
					
					if i['message'].find('招') != -1:
						exist_zhaobiao=exist_zhaobiao+int(1)
			else:
				print(jsonstrdata)
				# f.write(i['message']+'\n')
					# print('total_title_number: ',total_title_number)	
				
					# print('exist_zhaobiao: ',exist_zhaobiao)
		print('---------------------------------------------------总的------------------------------------')
		# f.close()
		print(exist_zhaobiao)
		# print(total_title_number)

	except Exception as e:
		print('errors')
		print(e)
		print('errors')
	

	# # current_time  = str(time.time())
	# current_time = str('1629260133')

	# print(create_safe(current_time))
